package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusDevice;
import com.ruoyi.business.service.IBusDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台设备Controller
 * 
 * @author asher
 * @date 2021-10-17
 */
@RestController
@RequestMapping("/business/device")
public class BusDeviceController extends BaseController
{
    @Autowired
    private IBusDeviceService busDeviceService;

    /**
     * 查询平台设备列表
     */
    @PreAuthorize("@ss.hasPermi('business:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusDevice busDevice)
    {
        startPage();
        List<BusDevice> list = busDeviceService.selectBusDeviceList(busDevice);
        return getDataTable(list);
    }

    /**
     * 导出平台设备列表
     */
    @PreAuthorize("@ss.hasPermi('business:device:export')")
    @Log(title = "平台设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusDevice busDevice)
    {
        List<BusDevice> list = busDeviceService.selectBusDeviceList(busDevice);
        ExcelUtil<BusDevice> util = new ExcelUtil<BusDevice>(BusDevice.class);
        return util.exportExcel(list, "平台设备数据");
    }

    /**
     * 获取平台设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:device:query')")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
    {
        return AjaxResult.success(busDeviceService.selectBusDeviceByDeviceId(deviceId));
    }

    /**
     * 新增平台设备
     */
    @PreAuthorize("@ss.hasPermi('business:device:add')")
    @Log(title = "平台设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusDevice busDevice)
    {
        return toAjax(busDeviceService.insertBusDevice(busDevice));
    }

    /**
     * 修改平台设备
     */
    @PreAuthorize("@ss.hasPermi('business:device:edit')")
    @Log(title = "平台设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusDevice busDevice)
    {
        return toAjax(busDeviceService.updateBusDevice(busDevice));
    }

    /**
     * 删除平台设备
     */
    @PreAuthorize("@ss.hasPermi('business:device:remove')")
    @Log(title = "平台设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds)
    {
        return toAjax(busDeviceService.deleteBusDeviceByDeviceIds(deviceIds));
    }
}
